# -*- coding: utf-8 -*-

from flask import Blueprint, render_template, current_app, send_from_directory, request, jsonify
import os
import time

mapping = Blueprint('mapping', __name__)

@mapping.route('/savemap', methods=['GET','POST'])
def savemap():
    filename = request.form.get('filename').decode('utf-8');
    # print(filename);
    map_dir = current_app.config['MAPDIR'];
    if filename != '':
        os.system("rosrun map_server map_saver -f" + " " + os.path.join(map_dir, filename))
        os.system("convert" + " " + map_dir + filename + ".pgm" + " " + map_dir + filename +".png")
        return jsonify({"code": 200, "error": ""})
    else:
        return jsonify({"code": 401, "error": "文件名空!"})